package com.axend.lib_base.view.dialog

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import com.axend.lib_base.R
import com.axend.lib_base.databinding.BaseDialogCustomClearBinding
import com.axend.lib_base.ext.click
import com.axend.lib_base.ext.dp2px

class CustomClearDialog(
    context: Context,
    title: String,
    content: String,
    onOkListener: DialogInterface.OnClickListener,
) : Dialog(context, R.style.Common_CustomDialog) {

    private var dialogBinding: BaseDialogCustomClearBinding

    init {
        dialogBinding =
            DataBindingUtil.inflate(layoutInflater, R.layout.base_dialog_custom_clear, null, false)
        setContentView(dialogBinding.root)
        setCanceledOnTouchOutside(false)
        val window = window
        window!!.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
        //设置提示框位置
        val lp = window!!.attributes
        //lp.gravity = Gravity.TOP | Gravity.LEFT;
        //lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
        //lp.x = DisplayUtils.dip2px(53);
        //lp.y = DisplayUtils.dip2px(186);
        lp.width = dp2px(280f)
        lp.height = dp2px(150f)
        window.attributes = lp
        dialogBinding.tvTips.text = content
        dialogBinding.btOk.setOnClickListener {
            onOkListener?.onClick(this, 0)
        }
        dialogBinding.btCancel.click {
            dismiss()
        }
    }
}